﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevTeam;
using System;
using System.Drawing;

namespace ConfExpert.Forms.SatinAlma
{
    public partial class SupheliFiyatK : XForm
    {
        public SupheliFiyatK()
        {
            InitializeComponent();
        }

        private void SupheliFiyatK_Load(object sender, EventArgs e)
        {
            gridView1.Init("CheckKumasBilancoK");
            gridView1.AddDetailGrid(gridView2, "ProductId");

            gridView2.RowCellStyle += gridView2_RowCellStyle;
            gridView2.MakeColumnInvisible("Scan");

            gridView1.FormatAsNumber(0, "Adet", "KonfMt");
            gridView2.FormatAsNumber(0, "KonfMt");
            gridView2.FormatAsNumber(2, "Fiyat", "TlFiyat");
            gridView1.AddSummary();
            gridView2.AddSummary("KonfMt");
            gridView1.FormatAsNumber(2, "StSapma", "MxKat", "MnKat");

            gridView1.MakeRowSelectable();
            gridView2.MakeReadOnly("Fiyat");

            GridFormatRule[] gridFormatRule = new GridFormatRule[3];
            FormatConditionRuleDataBar[] formatConditionRuleDataBar = new FormatConditionRuleDataBar[4];

            gridFormatRule[0] = new GridFormatRule();
            formatConditionRuleDataBar[0] = new FormatConditionRuleDataBar();
            gridFormatRule[0].Column = gridView1.Columns["StSapma"];
            formatConditionRuleDataBar[0].PredefinedName = "Yellow Gradient";
            gridFormatRule[0].Rule = formatConditionRuleDataBar[0];

            gridFormatRule[1] = new GridFormatRule();
            formatConditionRuleDataBar[1] = new FormatConditionRuleDataBar();
            gridFormatRule[1].Column = gridView1.Columns["MxKat"];
            formatConditionRuleDataBar[1].PredefinedName = "Raspberry Gradient";
            gridFormatRule[1].Rule = formatConditionRuleDataBar[1];

            gridFormatRule[2] = new GridFormatRule();
            formatConditionRuleDataBar[2] = new FormatConditionRuleDataBar();
            gridFormatRule[2].Column = gridView1.Columns["MnKat"];
            formatConditionRuleDataBar[2].PredefinedName = "Coral Gradient";
            gridFormatRule[2].Rule = formatConditionRuleDataBar[2];

            gridView1.FormatRules.AddRange(gridFormatRule);

            GridFormatRule gridFormatRuleX = new GridFormatRule();
            FormatConditionRuleDataBar formatConditionRuleDataBarX = new FormatConditionRuleDataBar();
            gridFormatRuleX.Column = gridView2.Columns["Fiyat"];
            formatConditionRuleDataBarX.PredefinedName = "Light Blue Gradient";
            gridFormatRuleX.Rule = formatConditionRuleDataBarX;

            gridView2.FormatRules.Add(gridFormatRuleX);

            gridView1.SetViewCaption("Artikel");
            gridView2.SetViewCaption("Konf Detayı");

            gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;
            btnKaydet.ItemClick += btnKaydet_ItemClick;
            gridView1.BestFitColumns();
            gridView2.BestFitColumns();
        }

        void gridView2_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.RowHandle > -1)
                if (e.Column.FieldName == "Fiyat")
                    e.Appearance.Font = new Font(DevExpress.Utils.AppearanceObject.DefaultFont, FontStyle.Bold);
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView2.BestFitColumns();
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView2.EndEditing();
            gridView2.Update("KonfId,Fiyat", "Konf");
            Notify("Kaydedildi.");

        }

        private void gridControl2_Click(object sender, EventArgs e)
        {

        }
    }
}
